/*
 * Copyright (c) 2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OHOS_AV_SYNC_MANAGER_H
#define OHOS_AV_SYNC_MANAGER_H

#include <set>
#include <mutex>

#include "av_sync_utils.h"
#include "av_trans_message.h"
#include "av_trans_types.h"

namespace OHOS {
namespace DistributedHardware {
constexpr uint32_t AV_SYNC_STREAM_COUNT = 2;

class AVSyncManager {
public:
    AVSyncManager();
    ~AVSyncManager();

    void AddStreamInfo(const AVStreamInfo &stream);
    void RemoveStreamInfo(const AVStreamInfo &stream);
    void HandleAvSyncMessage(const std::shared_ptr<AVTransMessage> &message);

private:
    void EnableSenderAVSync();
    void DisableSenderAVSync();
    void EnableReceiverAVSync(const std::string &groupInfo);
    void DisableReceiverAVSync(const std::string &groupInfo);
    bool MergeGroupInfo(std::string &syncGroupInfo);
    bool MergeGroupInfoInner(std::set<std::string> &groupInfoSet);
    std::string GetsyncGroupInfo(std::set<std::string> &groupInfoSet);

private:
    std::mutex listMutex_;

    std::vector<AVStreamInfo> streamInfoList_;
    AVTransSharedMemory sourceMemory_;
    AVTransSharedMemory sinkMemory_;
};
}
}
#endif